<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>示例</title>
</head>
<script type="text/javascript" src="/webjars/jquery/1.11.3/jquery.js"></script>
<script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/webjars/github-com-sentsin-layer/3.0.3/src/layer.js"></script>
<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
<body style="background-color: #f5f5f5;">
<#include "hearder.ftl"/>

<div class="form-group-in" style="padding-left: 50px;padding-right: 50px;padding-bottom: 10px;">
    <label style="font-size: 50px;">Groovy Tool demo</label>
    <form role="form">
        <button onclick="showVarDef()" type="button" style="font-size: 13px;margin-right: 10px;">变量定义</button>
        <button onclick="showIf()" type="button" style="font-size: 13px;margin-right: 10px;">判断条件</button>
        <button onclick="showResult()" type="button" style="font-size: 13px;margin-right: 10px;">返回结果运算</button>
        <button onclick="showParm()" type="button" style="font-size: 13px;margin-right: 10px;">调试运行参数</button>
        <textarea id="areaLabel" class="form-control"
                  style="background-color: #f5f5f5;font-weight:bold;margin-top: 5px;" rows="20">
        </textarea>
    </form>
</div>
</body>
<script>
    var varDef="            变量定义          \n" +
        "//注意，若需要运行调试传递参数，定义参数，从应用模型字段取值时需单独定义为一个参数\n" +
        "        //例如如:需要定义long23 字段值乘 0.2\n" +
        "        /*\n" +
        "        定义为: def long23Field = N_5352_1.long23.longValue();\n" +
        "                def result23 = long23Field * 0.2;\n" +
        "         */\n" +
        "\n" +
        "        //一个字节8位二进制位\n" +
        "        //byte:     1个字节  -128~127\n" +
        "        //char：    2个字节  0~65535\n" +
        "        //short：   2个字节  -32768~32767\n" +
        "        //int：     4个字节 -2147483648~2147483647\n" +
        "        //long：    8个字节 -9223372036854775807~9223372036854775807\n" +
        "\n" +
        "        //byte类型取值\n" +
        "        def byte23Field = N_5352_1.byte23.byteValue();\n" +
        "        //short 类型取值\n" +
        "        def short23Field = N_5352_1.short23.shortValue();\n" +
        "        //int类型取值\n" +
        "        def int23Field = N_5352_1.int23.intValue();\n" +
        "        //long类型取值\n" +
        "        def long23Field = N_5352_1.long23.longValue();\n" +
        "        //String类型取值\n" +
        "        def str02Field = N_5353_1.str02;\n" +
        "        //上一次的值\n" +
        "        def lastEngineHourCounter =  $lastState(\"engine_hour_counter\");\n" +
        "        def speedField = $lastState(\"speed\");\n" +
        "        def rsv03Field = $lastState(\"rsv_03\");\n" +
        "\n" +
        "        //位移后的判断是否为0或者1的值\n" +
        "        def short01Field = N_5352_1.short01.shortValue();\n" +
        "        def result01 = (short01Field >> 3 & 0x1) == 0;//与1比较\n" +
        "        def result02 = (short01Field >> 3 & 0x0) == 0;//与0比较\n" +
        "\n" +
        "        //直接固定值\n" +
        "        def intField = 0;\n" +
        "        //定义String字符串\n" +
        "        def positionDescripte = \"neutral\";\n" +
        "        //定义系数--可以用于计算X*N,X/N等   long23Field * threshold；\n" +
        "        def threshold = 0.01;\n" +
        "        //时间戳\n" +
        "        def timestampLocalField = new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss.S\").parse(N_5243_1.Timestamp_Local).getTime();\n" +
        "\n" +
        "        //计算后的值\n" +
        "        //与 二进制 1111逻辑与\n" +
        "        def short03Field = N_5352_1.short03.shortValue();\n" +
        "        def result03 = short03Field & 0xFF;\n" +
        "        //与 二进制 0011逻辑与\n" +
        "        def result04 = short03Field & 0x03;\n" +
        "        //加减乘除\n" +
        "        def result05 = short03Field-12;\n" +
        "        def result06 = short03Field+12;\n" +
        "        def result07 = short03Field/12;\n" +
        "        def result08 = short03Field*0.12;\n" +
        "\n" +
        "        //三目运算后的值\n" +
        "        def short04Field = N_5352_1.short04.shortValue();\n" +
        "        def result09 = (short04Field & 0x1) ? \"是\":\"否\"\n" +
        "        def result10 = short04Field >0 ? short04Field:0;\n" +
        "\n" +
        "        //位移后 判断是否为1，是则报警，否则正常\n" +
        "        def rsvField = N_5352_1.short04.shortValue();\n" +
        "        def result11 =  (rsvField >> 2 & 0x1) == 0 ? \"正常\" : \"报警\";";
    $("#areaLabel").html(varDef);
    function showVarDef() {
        $("#areaLabel").html(varDef);
    }


    function showResult() {
        var text="结果";
        $("#areaLabel").html(text);
    }


    function showIf() {
        var text = "def field01 = 1223;\n" +
            "        def field02 = \"测试\";\n" +
            "        def field03 = 23.234;\n" +
            "\n" +
            "        //number类型判断\n" +
            "        //大于\n" +
            "        field01 > 1300\n" +
            "        //小于\n" +
            "        field01 < 1300\n" +
            "        //不等\n" +
            "        field01 != 1300\n" +
            "        //等于\n" +
            "        field01 == 1300\n" +
            "\n" +
            "        //string类型判断---不建议使用string类型判断\n" +
            "        field02 == \"测试\"\n" +
            "        field02 != \"测试\"\n" +
            "\n" +
            "        //逻辑与\n" +
            "        field01 & 0x1\n" +
            "        //条件与\n" +
            "        (field01<1300) && (field01 != 1300)\n" +
            "        //条件或\n" +
            "        (field01<1300) || (field01 != 1300)\n" +
            "        //条件非\n" +
            "        !(field01<1300)";
        $("#areaLabel").html(text);
    }

    function showParm() {
        var text = "//需填写的参数为带有N_{模型id}_1等的数据，这些在运行时会替换为填写的参数\n" +
            "\n" +
            "        def int23Field = N_5352_1.int23.intValue();\n" +
            "        //long类型取值\n" +
            "        def long23Field = N_5352_1.long23.longValue();\n" +
            "\n" +
            "        //参数:int23Field,long23Field  输入框中填写: 123,5567\n" +
            "        //int23Field = 123,long23Field = 5567";
        $("#areaLabel").html(text);
    }

</script>
<style>
    button{
        padding: 0.1em 1em;
        text-align: center;
        text-decoration: none;
        color: #2194E0;
        font-size: 18px;
        display: inline-block;
        position: relative;
        overflow: hidden;
        border: none;
        background-color: #f5f5f5;
    }
</style>
</html>